import requests

TOKEN = 'Basic cGxhdGZvcm06ZUted0g3OSZOV3FI'
URL = 'http://k8s-api.patsnap.info/envs'


def fetch_config_from_apollo(app_id, cluster, namespace):
    url = f"{URL}?service_name={app_id}&env={namespace}&team=data&region={cluster}&language=python"
    headers = {"Authorization": TOKEN}
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        config_data = response.json()
        if config_data.get('error_code') == 0:
            return config_data.get('data')
    raise Exception('get apollo config err')



if __name__ == '__main__':
    print(fetch_config_from_apollo('s-data-npd-flink-etl', 'ap-beijing', 'tags_to_dwd'))